package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.BonusHandler;
import com.cungmua.app.model.request.BonusRequest;
import com.cungmua.app.model.response.BonusResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/1/14.
 */
public class BonusTask extends AuthenticatedTask<BonusRequest, Void, BonusResponse> {
    private Context context;
    private BonusHandler handler;
    public BonusTask(Context context, BonusHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected BonusResponse doInBackground() throws RetrofitError {
        BonusRequest request = params[0];

        if(request.getBonusCode()!=null) {
            return CungMuaAPI.getService().subMitBonus(request.toFieldMap());
        }else{
            return CungMuaAPI.getService().getBonus(request.toFieldMap());
        }

    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(BonusResponse bonusResponse) {
        handler.onBonus(bonusResponse);
    }
}
